<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/static/weui/css/weui.css"/>
    <link rel="stylesheet" href="/static/weui/css/weuix.css"/>

    <script src="/static/weui/js/zepto.min.js"></script>
    <script src="/static/weui/js/zepto.weui.js"></script>
    <script>
        $(function () {
            $(document).on("click", "#btn", function () {
                var name = $.trim($("[name='name']").val());
                if (name == "") {
                    $.toptip("请输入姓名");
                    return false;
                }
                var num = $.trim($("[name='num']").val());
                if (num == "") {
                    $.toptip("请输入学号");
                    return false;
                }
                // var cid = $.trim($("[name='cid']").val());
                // if (cid == "") {
                //     $.toptip("请选择班级");
                //     return false;
                // }

                $.ajax({
                    url:"",    //请求的url地址
                    dataType:"json",   //返回格式为json
                    async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data:{name: name, num: num},    //参数值
                    type:"get",   //请求方式
                    beforeSend:function(){
                        //请求前的处理
                    },
                    success:function(res){
                        //请求成功时处理
                        if (res.code == 200) {

                            $.toptip("提交成功", 'success');
                            window.location.href = "{:url('/mobile/index/answer')}?aid=" + res.data.aid + '&sid=' + res.data.sid;
                        } else {

                            $.toptip(res.message);
                        }
                    },
                    complete:function(){
                        //请求完成的处理
                    },
                    error:function(){
                        //请求出错处理

                        $.toptip('网络错误，稍后重试');
                    }
                });

            })
            //解决表单控件不能回弹 只有微信ios有这个问题
            $("input,select,textarea").blur(function () {
                setTimeout(() => {
                    const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
                    window.scrollTo(0, Math.max(scrollHeight - 1, 0));
                }, 100);
            })

        });


        function cleartxt(obj) {
            $(obj).prev().find('.weui-input').val("");
            return false;
        }


    </script>
    <style>
        .weui-label {
            width: 60px;
        }

        .weui-input {
            width: 85%;
        }
        .page-hd{
            padding: 40px 5px;
        }

        .logo {
            width: 30%;
        }
    </style>
</head>

<body ontouchstart>
<div class="page-hd">
    <h1 class="page-hd-title" style="text-align: center">
        <img src="/static/weui/images/logo.png" class="logo"><br/><br/>
        请登记信息参与基础部各课程知识测验<br/>
        <span style="color: red;font-size: 14px">每人只有一次答题机会，请大家认真答题</span>
    </h1>
    <p class="page-hd-desc"></p>
</div>


<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">姓名</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" name="name" placeholder="请输入姓名" type="text">
            <i style="float: right;line-height: 25px;" class="weui-icon-clear" onclick="cleartxt(this)"></i>
        </div>

    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">学号</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" name="num" placeholder="请输入学号" type="number">
            <i style="float: right;line-height: 25px;" class="weui-icon-clear" onclick="cleartxt(this)"></i>
        </div>

    </div>

    <div style="display:none;" class="weui-cell weui-cell_select weui-cell_select-after">
        <div class="weui-cell__hd">
            <label for="" class="weui-label">班级</label>
        </div>
        <div class="weui-cell__bd">
            <select class="weui-select" name="cid">
                {php} foreach($classes as $value){ {/php}
                <option value="{:$value['id']}">{:$value['name']}</option>
                {php}}{/php}
            </select>
        </div>
    </div>

</div>


<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="btn">确定</a>
</div>



<br>
<br>

<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__text">Copyright &copy; 上海工商职业技术学院</p>
</div>
</body>
</html>